<?php



    if (!empty($_POST)) {

        if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])) {

            $pid = $_POST['pid'];
            $sql = "select * from `cate` where `pid`='$pid'";

            $result = mysqli_query($link,$sql);

            while ($arr = mysqli_fetch_assoc($result)){

                $data[] = $arr;
            };

            print_r(json_encode($data));die;

            };

        $url = null;
        $pic_name = null;

        //print_r($_FILES);die;

        if (!empty($_FILES['pic'])){


            foreach ($_FILES['pic'] as $key => $value){
                foreach ($value as  $v) {
                    $pic[$key]= $v;
                }
            }
            //print_r($pic);die;
            //$pic = $_FILES['pic'];
            include_once LIB_PATH.'file.php';

            $_file = getfile($pic);

            $ins['url'] = $_file['url'];
            $ins['pic_name'] = $_file['pic'];
            //echo 1;die;
        }

        //echo 2;die;
        $ins['title'] = $_POST['title'];
        $ins['type'] = $_POST['type'];
        $ins['author'] = $_POST['author'];
        $ins['content'] = $_POST['content'];
        $ins['status'] = !empty($_POST['status'])?$_POST['status']:0;
        $ins['send_user'] = $_SESSION['admin']['username'];

        // $sql = "insert into `news` (`title`,`type`,`author`,`content`,`send_user`,`url`,`pic_name`) values ('$title','$type','$author','$content','$send_user','$url','$pic_name')";

        // mysqli_query($link,$sql);
        $_rows = getInsert('news',$ins);
        if ($_rows > 0) {
            echo '<script type="text/javascript">alert("添加成功！");self.location.href="index.php?c=news&a=list&admmin=1";</script>';die;
        }else{
            echo '<script type="text/javascript">alert("添加失败！");history.go(-1);</script>';die;
        }
    }




?>